package com.grf.hadoop.order_grouping;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class OrderGroupingComparator extends WritableComparator {

    protected OrderGroupingComparator(){
        super(OrderBean.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        //只要id相同，就认为是相同的key
        OrderBean aOrder = (OrderBean) a;
        OrderBean bOrder = (OrderBean) b;
        int res;
        if (aOrder.getId() > bOrder.getId()) {
            res = 1;
        } else if(aOrder.getId() < bOrder.getId()) {
            res = -1;
        } else {
            res = 0;
        }
        return res;
    }
}
